home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 456 < prev    next >
Internet Message Format  |  1996-08-06  |  4KB

  1. Path: tbj.dec.com!diamond
  2. From: diamond@tbj.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: sizeof(char) ~= sizeof(float)
  5. Date: 28 Feb 1996 08:07:26 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4h12fu$6ct@usenet.pa.dec.com>
  8. References: <WALD.96Feb24131532@woodpecker.lcs.mit.edu> <4gr3d1$dca@usenet.pa.dec.com> <TANMOY.96Feb25203514@qcd.lanl.gov>
  9. Reply-To: diamond@tbj.dec.com (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tbj.dec.com
  11.  
  12. In article <TANMOY.96Feb25203514@qcd.lanl.gov>, tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) writes:
  13. >In article <4gr3d1$dca@usenet.pa.dec.com>
  14. >diamond@tbj.dec.com (Norman Diamond) writes:
  15. >>Rumor has it that Technical Corrigendum 2 will change the standard so that
  16. >>unsigned char cannot have any holes.  Signed char will still be allowed to
  17. >>have holes, and char will still have to behave either as unsigned char (no
  18. >>holes) or as signed char (identical holes).
  19.  
  20. >What happens to the requirement that positive signed integral values
  21. >have to have the same representation as the corresponding unsigned
  22. >integral value? Coupled with the requirement of pure binary
  23. >representation [...] it seems to say that if unsigned char can't have
  24. >holes, neither can signed char
  25.  
  26. ANSI Classic section 3.1.2.5, freshly unpacked in this month's new office,
  27. page 24 lines 3 to 5:  "The range of nonnegative values of a signed
  28. integer type is a subrange of the corresponding unsigned integer type,
  29. and the representation of the same value in each type is the same."
  30. If unsigned char can hold the value 255 but signed char cannot, there is
  31. no violation of the "subrange" requirement and there is no signed
  32. representation to be matched.  Even if unsigned char can hold the value
  33. 65535 but signed char cannot hold values 65535 or 255, no problem.
  34.  
  35. >unless whether a certain bit contributes to the value or not depends on the
  36. >sign bit; I assume such `holes' are allowed?
  37.  
  38. I have a vague impression that this kind of hole is not allowed.  A hole
  39. is either part of the representation of the type or it is not.
  40.  
  41. >I was assuming that the rumored TC2 interpretation will be adopted.
  42. >The argument is that in 
  43. >  float x, y;
  44. >  unsigned char *xx=(void*)&x, *yy=(void*)&y;
  45. >copying (or comparing) sizeof(float) unsigned chars from xx to yy must
  46. >manage to copy (or compare) x from y.
  47.  
  48. Or more precisely:
  49.    float x, y;
  50.    unsigned char (*xx)[sizeof(float)]=(void*)&x,
  51.                  (*yy)[sizeof(float)]=(void*)&y;
  52.    *yy = *xx;
  53. Yes, if the rumored TC2 interpretation is adopted, I think this will
  54. have to work.
  55.  
  56. >Whether or not `char' can have holes, if there are say two
  57. >representations of 0 (sign-magnitude / one's complement etc.) a copy
  58. >of char can change one representation to the other.
  59.  
  60. I think so.
  61.  
  62. [Without, or before, TC2]:
  63. >>If you use memcpy or possibly if you play tricks with union types, you can
  64. >>force it to copy all the bits.
  65.  
  66. >This was a free-standing implementation, and memcpy may be absent.
  67.  
  68. I think suitable union types would still work.  But now I wonder, if the
  69. programmer knows that the objects are floats, why not just assign floats?
  70.  
  71. [Regardless of TC2, I think]:
  72. >(In a hosted implementation, as all read/write is done as if through
  73. >getc/putc which handles unsigned char values, and binary files written
  74. >out must be read back unchanged, the situation is impossible).
  75.  
  76. Actually there's already a problem here.  If there are two representations
  77. of 0 but all read/write is done as if through functions which convert
  78. between int and unsigned char, it is impossible to read some stuff back
  79. unchanged.  I hope a DR was submitted about this a few years ago.
  80. --
  81.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  82. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  83. license, so I can drive in any lane I want, and no innocent victim gets to call
  84. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  85.